﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MinhTuan;
namespace Products
{
    public class Brand
    {
        #region //attribute
            private Int32 _Brand_Id;
            private String _Brand_Name;
            private String _Brand_Title;
            private String _Brand_Image;
            private Int32 _Brand_Sort;
            private Boolean _IsActive;

        #endregion
         public Brand()
        {

        }

        #region // initialize

                    public Brand(
			        Int32 Brand_Id,
			        String Brand_Name,
			        String Brand_Title,
			        String Brand_Image,
			        Int32 Brand_Sort,
			        Boolean IsActive
                    )
                {		_Brand_Id=Brand_Id;
		        _Brand_Name=Brand_Name;
		        _Brand_Title=Brand_Title;
		        _Brand_Image=Brand_Image;
		        _Brand_Sort=Brand_Sort;
		        _IsActive=IsActive;
                }
               
        	        public Int32 Brand_Id
	            {
	              get { return _Brand_Id; }
	              set { _Brand_Id = value; }
	             }

	        public String Brand_Name
	            {
	              get { return _Brand_Name; }
	              set { _Brand_Name = value; }
	             }

	        public String Brand_Title
	            {
	              get { return _Brand_Title; }
	              set { _Brand_Title = value; }
	             }

	        public String Brand_Image
	            {
	              get { return _Brand_Image; }
	              set { _Brand_Image = value; }
	             }

	        public Int32 Brand_Sort
	            {
	              get { return _Brand_Sort; }
	              set { _Brand_Sort = value; }
	             }

	        public Boolean IsActive
	            {
	              get { return _IsActive; }
	              set { _IsActive = value; }
	             }


        #endregion
        #region//method
            public static Brand GetBrandDetail(Int16 Brand_Id)
            {
                Brand mybrand = new Brand();
                //try {
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "sp_Product_GetBandDetail";
                    Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value = Brand_Id;
                    SqlDataReader reader;
                    reader = Access.mySqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        mybrand = new Brand(Convert.ToInt16(reader["Brand_Id"].ToString()), reader["Brand_Name"].ToString(), reader["Brand_Title"].ToString(),
                            reader["Brand_Image"].ToString(), Convert.ToInt16(reader["Brand_Sort"].ToString()), Convert.ToBoolean(reader["IsActive"].ToString()));                   
                    }
                    reader.Close();
                    Access.ClosedAccess();
                    return mybrand;
                //}
                //catch {
                //    Access.ClosedAccess();
                //    return mybrand;
                //}
            }

            public static DataTable GetBrand()
            {
                DataTable tbl = new DataTable();
                try
                {
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "sp_Product_Getbrandforlist";
                    SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    Access.ClosedAccess();
                    tbl = ds.Tables[0];
                    return tbl;

                }
                catch
                {
                    Access.ClosedAccess();
                    return tbl;
                }

            }

        #endregion
    }
}
